<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Sign extends CI_Controller {
	public function _load()
	{
		$this->load->model('User_model');
		$this->load->library('user_verification');
	}
	function __construct()
	{
		parent::__construct();
		$this->_load();
	}
	function index()
	{
		$this->login();
	}
	public function login()
	{
		$data['tips_sms']['login'] = array('type'=>'alert-info','title'=>'提示!','info'=>'　留意周边环境，注意保护账号隐私信息.');
		$data['tips_sms']['register'] = array('type'=>'alert-info','title'=>'提示!','info'=>'　留意周边环境，注意保护账号隐私信息.');
		$data['tips_sms']['dom_show'] = 'login';
		$this->view_tpl($data);
	}
	public function loginout()
	{
	}
	public function doLogin()
	{
		if(!isset($_POST['user']) || !isset($_POST['pwd']))
		{
			$this->login();
			exit();
		}
		$data['user'] = $_REQUEST['user'];
		$data['pwd'] = $_REQUEST['pwd'];
		$reVerifica = $this->user_verification->is_verifica($data);
		$data['tips_sms']['register'] = array('type'=>'alert-info','title'=>'提示!','info'=>'　留意周边环境，注意保护账号隐私信息.');
		$data['tips_sms']['dom_show'] = 'login';
		switch($reVerifica)
		{
			case 0:
				$data['tips_sms']['login'] = array('type'=>'alert-error','title'=>'错误!','info'=>'　请重新核对输入正确用户名登录系统.');
				$this->view_tpl($data);
				break;
			case 2:
				$data['tips_sms']['login'] = array('type'=>'alert-error','title'=>'错误!','info'=>'　用户名和输入密码不匹配，请重新核对.');
				$this->view_tpl($data);
				break;
			case 1:
				$this->input->set_cookie(array('name'=>'is_login','value'=>1,'expire'=>10000000));
				redirect('member/dashboard', 'location', 303);
				break;
		}
	}
	public function view_tpl($data)
	{
		$this->load->view('member/login',$data);
	}
	public function register()
	{
		if(!isset($_POST['user']) || !isset($_POST['pwd']))
		{
			$this->login();
			exit();
		}
		$data['user'] = $_POST['user'];
		$data['pwd'] = $this->common_func->createPwd($_POST['pwd']);
		if($this->user_verification->is_user_name($_POST['user']) != 0)
		{
			$this->login();
			exit;
		}
		$this->User_model->addUser($data);
//		
		$data['pwd'] = $_POST['pwd'];
		$reVerifica = $this->user_verification->is_verifica($data);
		$this->input->set_cookie(array('name'=>'is_login','value'=>1,'expire'=>10000000));
		redirect('member/dashboard', 'location', 303);
	}
}